package com.huluobo.a2207monthdemo

import android.content.Intent
import androidx.appcompat.app.AppCompatActivity
import android.os.Bundle
import android.util.Log
import android.view.View
import android.webkit.JavascriptInterface
import com.blankj.utilcode.util.SPUtils
import com.huluobo.a2207monthdemo.databinding.ActivityMainBinding
import com.huluobo.a2207monthdemo.sign.SignActivity
import com.huluobo.base.mvvm.BaseActivity
import com.huluobo.base.net.Const

class MainActivity : BaseActivity<ActivityMainBinding, MainViewModel>() {
    override fun initData() {
    }

    override fun initView() {
        initWebView()
    }

    private fun initWebView() {
        val listener = MainWebViewJavaScriptFun()
        val home = SPUtils.getInstance().getString(Const.PARAM_HOME)
        binding.mainX5.loadUrl(home)
        binding.mainX5.overScrollMode = View.OVER_SCROLL_ALWAYS
        binding.mainX5.addJavascriptInterface(listener, "androidinfo")
    }

    inner class MainWebViewJavaScriptFun {
        @JavascriptInterface
        fun androidsign(id: String) {
            //打开签到activity
            start(SignActivity::class.java)
        }

        @JavascriptInterface
        fun androidaddculture(id: String) {
            //打开新闻activity
            Log.i("TagA", "新闻")
        }

        @JavascriptInterface
        fun androidparking(id: String?) {
            //车位申请
            Log.i("TagA", "车位申请")
        }

        @JavascriptInterface
        fun androidapply(id: String?) {
            //我的申请
            Log.i("TagA", "我的申请")
        }

        @JavascriptInterface
        fun androidvisit(id: String?) {
            //来访预约
            Log.i("TagA", "来访预约")
        }

        @JavascriptInterface
        fun androidpatrol(id: String?) {
            //巡更管理
            Log.i("TagA", "巡更管理")
        }

        @JavascriptInterface
        fun androidnews(id: String?) {
            Log.i("TagA", "新闻")
        }

        @JavascriptInterface
        fun androidnoticelist(id: String?) {
            Log.i("TagA", "公告")
        }

        @JavascriptInterface
        fun androidrepair(id: String?) {
            //维修管理
            Log.i("TagA", "维修管理")
        }

        @JavascriptInterface
        fun androidaddrepair(id: String?) {
            //添加维修
            Log.i("TagA", "添加维修")
        }

        @JavascriptInterface
        fun androidaddnotice(id: String?) {
            //公告管理
            Log.i("TagA", "添加公告")
        }

        @JavascriptInterface
        fun androidculture(id: String?) {
            //文化管理
            Log.i("TagA", "文化管理")
        }

        @JavascriptInterface
        fun androidnotice(id: String?) {
            //公告管理
            Log.i("TagA", "公告")
        }

        @JavascriptInterface
        fun androidattendance(id: String?) {
            //考勤管理
            Log.i("TagA", "考勤")
        }

        @JavascriptInterface
        fun androidproperty(id: String?) {
            //物业审核
            Log.i("TagA", "物业审核")
        }

        @JavascriptInterface
        fun androidcheckculture(id: String?) {
            //文化审核
            Log.i("TagA", "文化审核")
        }

        @JavascriptInterface
        fun androidpeople(id: String?) {
            //人资管理
            Log.i("TagA", "人资管理")
        }
    }

    fun start(clazz: Class<*>) {
        val intent = Intent(this, clazz)
        startActivity(intent)
    }
}